/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.cloudminga.database;

/** This class is used to getting the user's Backup information,
 *  Method get_TableModel(String email) takes a argument as String
 *  and returns the TableModel object in which all user's backup information
 *  are stored by get_TableModel(String email) method....
 * @author Shailendra
 */
import java.sql.*;

public class DataBase_UserBackupInfo
{
        Statement statement;
        Connection connection=null;
        ResultSet resultSet=null;
        CallableStatement callableStatement;
        ResultSetMetaData resultsetMetaData;
        String query;
        String email_Id;
        TableModel table_Model;
         int colCount=0;
         int rowCount=0;
       
      public DataBase_UserBackupInfo()
      {
       try
        {
            // Establising database connection
            Class.forName("net.sourceforge.jtds.jdbc.Driver");
            connection = DriverManager.getConnection("jdbc:jtds:sqlserver://mssql502.ixwebhosting.com/C230527_masterdatabase","C230527_sumit","Globus1234");
           
         }  // End of try

         catch(Exception exception)
         {
             exception.printStackTrace();
         }// End of catch
      }//end of constructor

// Method created for set the values in ModelTable
     public TableModel get_TableModel(String email)
      {
         this.email_Id=email;
          try
          {
            callableStatement=connection.prepareCall("{call sp_Pomblast_GetBackupsInfoByUser(?)}",ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
            callableStatement.setString(1, email_Id);
            resultSet=callableStatement.executeQuery();
            // rsmt is ResultSetMetaData to find out the total columns of the table
            resultsetMetaData=resultSet.getMetaData();
            colCount=resultsetMetaData.getColumnCount();

            resultSet.last();
            rowCount=resultSet.getRow();
            resultSet.beforeFirst();
            System.out.println("number of rows are :  "+rowCount);
            table_Model=new TableModel(rowCount,colCount);
            resultSet.beforeFirst();


              table_Model=new TableModel(rowCount,colCount);
               if(resultSet.next())
               for(int temp=0;temp<resultsetMetaData.getColumnCount();temp++)
               {
                   table_Model.setValueAt(0,temp,resultSet.getString(temp+1));
               }
           else
               System.out.println("invalid user");
        }
        catch(Exception exception)
        {
            exception.printStackTrace();
        }
          return table_Model;
    }
}
